package com.doyens.gmall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.doyens.gmall.common.result.Result;
import com.doyens.gmall.model.product.BaseTrademark;
import com.doyens.gmall.product.service.BaseTrademarkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Classname:BaseTrademarkController
 * PackageName:com.doyens.gmall.product.controller
 *
 * @Author:uyijk
 * @Create:2023/7/26 15:10
 * @Version: 1.0
 */
@RestController
@RequestMapping("/admin/product/baseTrademark")
@Api(tags = "品牌管理")
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;
    @ApiOperation(value = "分页查询")
    @GetMapping("/{page}/{size}")
    public Result index(@PathVariable("page")Long page,@PathVariable("size")Long size){
        IPage<BaseTrademark> trademarkIPage = baseTrademarkService.getPage(page,size);
        return Result.ok(trademarkIPage);
    }

    @ApiOperation(value = "添加品牌")
    @PostMapping("save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    @ApiOperation(value = "根据主键修改品牌")
    @PutMapping("update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("根据主键删除品牌")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable("id")Long id){
        baseTrademarkService.deleteById(id);
        return Result.ok();
    }

    @ApiOperation("根据主键查询品牌")
    @GetMapping("get/{id}")
    public Result<BaseTrademark> get(@PathVariable("id") Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    @ApiOperation("获取所有品牌列表")
    @GetMapping("getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> trademarkList = baseTrademarkService.getTrademarkList();
        return Result.ok(trademarkList);
    }
}
